package com.lxr0860.lxr0860production_test.base;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.provider.Settings;
import android.util.Log;

import com.lxr0860.lxr0860production_test.utils.DataUtils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Method;

public class DevNumberUtils {
    private static DevNumberUtils devNumberUtils;
    private static Context mContext;

    private DevNumberUtils(){}

    public static DevNumberUtils getInstance(Context context){

        if (devNumberUtils == null) {
            devNumberUtils = new DevNumberUtils();
        }
        mContext = context;
        return devNumberUtils;
    }


    /**
     * 获取BtMac地址
     * @return
     */
    public static String getBTMac() {
       return "";
    }

    /**
     * 获取WifiMac地址
     * @return
     */
    public static String getWifiMac() {

        return "";
    }

    /**
     * 获取FlashID
     * @return
     */
    public  String getFlashID() {
        return "";
    }

    /**
     * 获取sam卡号
     *
     */
    public  String getSamSN() {

        return "fail";
    }


    /**
     * 获取IMEI号
     * @return
     */
    public  String getIMEI() {

        return "fail";
    }

    /**
     * 获取起爆器编号
     * @return
     */
    public  String getDetonatorno() {

        return "fail";
    }

    /**
     * 获取终端编号
     * @return
     */
    public  String getTerNo() {
        return "fail";
    }

    /**
     * 获取序列号
     *
     * @return
     */
    public  String getDeviceSN() {

        String serial = "fail";
        try {
            Class<?> c = Class.forName("android.os.SystemProperties");
            Method get = c.getMethod("get", String.class);
            serial = (String) get.invoke(c, "ro.serialno");
        } catch (Exception e) {
            e.printStackTrace();

        }
        return serial;

    }

    /**
     * 获取摄像头，tp相关信息
     * @return
     */
    public  String[] getCamera_TPInfo(){
        String str_path = "/sys/devices/platform/harewareinfo/hardwareinfo";
        String[] split;

        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(str_path));
            String str;

            String allstr = "";
            while ((str = reader.readLine()) != null) {

                allstr += str + " ";
                Log.e("readLine", str);
            }
            split = allstr.split(" ");
            for (int i = 0; i < split.length; i++) {
                Log.e("split", "split" + i + ":" + split[i]);
            }
            return split;
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }

    /**
     * 获取条码型号
     * @return
     */
    public  String getBarcodeID() {
        int scannerBarcodeModel = Settings.System.getInt(mContext.getContentResolver(),
                "scanner_barcode_model", 0);

        return scannerBarcodeModel==0?"fail":scannerBarcodeModel+"";
    }


    /**
     * 获取mcu版本
     * @return
     */
    public  String getMCUVS(){
            return "fail";

    }

    /**
     *  获取app版本
     * @return
     */
    public  String getAPPVS(){
        PackageManager packageManager = mContext.getPackageManager();
        String packageName = mContext.getPackageName();
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
            return packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return "fail";
        }
    }
}
